/*
 * test.c
 *
 *  Created on: Feb 25, 2014
 *      Author: tiphan
 */

#include <msg/msg.h>
#include <xbt/sysdep.h>
#include <xbt/log.h>
#include <xbt/asserts.h>
#include "common.h"
#include "hdfs.h"

void read_config_file(const char* file_name);

int main (int argc, char* argv[]) {
	read_config_file("conf.txt");
	data_distributing();
	return 0;
}

void read_config_file(const char* file_name) {
	char property[256];
	FILE* file;

	/* Set the default configuration. */
	config.chunk_size = 67108864;
	config.chunk_count = 0;
	config.chunk_replicas = 3;

	/* Read the user configuration file. */

	file = fopen(file_name, "r");

	xbt_assert(file != NULL, "Error reading cofiguration file: %s", file_name);

	while (fscanf(file, "%256s", property) != EOF) {
		if (strcmp(property, "chunk_size") == 0) {
			fscanf(file, "%lf", &config.chunk_size);
			config.chunk_size *= 1024 * 1024; /* MB -> bytes */
		}
		else if (strcmp(property, "chunk_count") == 0) {
			fscanf(file, "%d", &config.chunk_count);
		}
		else if (strcmp(property, "chunk_replicas") == 0) {
			fscanf(file, "%d", &config.chunk_replicas);
		}
		else if (strcmp(property, "number_of_workers") == 0) {
			fscanf(file, "%d", &config.number_of_workers);
		}
		else if (strcmp(property, "number_of_datanodes") == 0) {
			fscanf(file, "%d", &config.number_of_datanodes);
		}
		else {
			printf("Error: Property %s is not valid. (in %s)", property,
					file_name);
			exit(1);
		}
	}

	fclose(file);
//	return 0;
}
